package com.snda.lib.ui;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;

public class AutoDispearProcessDlg {

	private ProgressDialog progressDialog = null;
	private static AutoDispearProcessDlg dlg = new AutoDispearProcessDlg();
	private Handler timerHandler = new Handler();

	public static AutoDispearProcessDlg getInstance() {
		return dlg;
	}

	private AutoDispearProcessDlg() {
	}

	public ProgressDialog getProcessDlg() {
		return this.progressDialog;
	}

	public void show(Context cxt, CharSequence strTitle, CharSequence strMessage) {
		dismiss();

		progressDialog = ProgressDialog.show(cxt, strTitle, strMessage, true);
		timerHandler.postDelayed(runTask, 1000 * 10);
	}

	public void dismiss() {
		timerHandler.removeCallbacks(runTask);

		if (progressDialog != null) {
			progressDialog.dismiss();
			progressDialog = null;
		}
	}

	private Runnable runTask = new Runnable() {

		public void run() {

			ProgressDialog dlg = AutoDispearProcessDlg.getInstance()
					.getProcessDlg();
			if (dlg != null) {
				dlg.dismiss();
				dlg = null;
			}
		}
	};

}